<?php

namespace App\Http\Controllers\Admin\qyf;

use App\Common\Responses;
use App\Http\Controllers\Controller;
use App\Models\Store;
use Illuminate\Http\Request;

class Stroe extends Controller
{
    //查看门店
    function lookStores(){
       $data= Store::lookStores();
        return Responses::success($data);
    }
    //添加门店
    function addStore(Request $request){
        $param = $this->getParam1($request);
        $data= Store::addStore($param);
        return Responses::success($data);
    }
    //修改门店信息
    function updateStore(Request $request){
        $id= (int)$request->post('id');
        $param = $this->getParam1($request);
        $data= Store::updateStore($id,$param);
        return Responses::success($data);
    }
    //删除门店信息
    function removeStore(Request $request){
        $id= (int)$request->post('id');
        $data= Store::removeStore($id);
        return $data?
            Responses::success($data,200,'删除成功'):
            Responses::error($data,404,'没有找到该数据');
    }
    /**
     * @param Request $request
     * @param $param
     * @return void
     */
    private function getParam(Request $request, &$param): void
    {
        $name = (string)$request->post('name');
        $logo = (string)$request->post('logo');
        $longitude = (string)$request->post('longitude');
        $latitude = (string)$request->post('latitude');
        $phone = (string)$request->post('phone');
        $param = [
            'name' => $name,//获取门店名称
            'logo' => $logo,//门店图片
            'longitude' => $longitude,//经度
            'latitude' => $latitude,//纬度
            'phone' => $phone//门店联系方式
        ];
    }


    //获取位置信息
//     function    public{
//
//        return Responses::success(['success'=>$data]);
//        }
    /**
     * @param Request $request
     * @return string[]
     */
    private function getParam1(Request $request): array
    {
        $name = (string)$request->post('name');
        $logo = (string)$request->post('logo');
        $latitude = (string)$request->post('latitude');
        $longitude = (string)$request->post('longitude');
        $phone = (string)$request->post('phone');
        $param = [
            'name' => $name,//获取门店名称
            'logo' => $logo,//门店图片
            'latitude' => $latitude,//纬度
            'longitude' => $longitude,//经度
            'phone' => $phone//门店联系方式
        ];
        return $param;
    }

}
